<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #sort="{ record }">
        <a-input v-model="record.sort" type="number" @input="changeSort(record)" placeholder="请输入排序"></a-input>
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import serviceGroup from '@/api/logistics/serviceGroup'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()

const changeSort = async (record) =>{
    let res = await serviceGroup.update(record.id,record)
    if(!res.success){
      Message.error(res.message)
      return false ;
    }
    Message.success(res.message)
    crudRef.value.refresh()
}

const options = reactive({
  id: 'service_group',
  pageLayout: 'fixed',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'drawer',
    width: 600
  },
  requestParams:{
    orderBy:'sort',
    orderType:'desc'
  },
  api: serviceGroup.getList,
  recycleApi: serviceGroup.getRecycleList,
  add: {
    show: true,
    api: serviceGroup.save,
    auth: ['logistics:serviceGroup:save']
  },
  edit: {
    show: true,
    api: serviceGroup.update,
    auth: ['logistics:serviceGroup:update']
  },
  delete: {
    show: true,
    api: serviceGroup.deletes,
    auth: ['logistics:serviceGroup:delete'],
    realApi: serviceGroup.realDeletes,
    realAuth: ['logistics:serviceGroup:realDeletes']
  },
  recovery: {
    show: true,
    api: serviceGroup.recoverys,
    auth: ['logistics:serviceGroup:recovery']
  }
})

const columns = reactive([
  {
    title: "主键",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入主键"
    }
  },
  {
    title: "分组名称",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入分组名称"
    }
  },
  {
    title: "排序",
    dataIndex: "sort",
    formType: "input",
  },
  {
    title: "分组状态",
    dataIndex: "status",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    // search: true,
    commonRules: {
      required: true,
      message: "请输入分组状态"
    },
    hide: true
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default { name: 'logistics:serviceGroup' } </script>